package com.zhiyou100.servlet.management.student;

import com.zhiyou100.entity.Student;
import com.zhiyou100.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Description TODO 获取所有的学生
 * @packageName ${PACKAGE_NAME}
 * @ClassName ${NAME}
 * @Author yang
 * @Date 8/13/20 10:08
 * @Version V1.0
 */
@WebServlet(name = "GetAll", urlPatterns = "/management/student/GetAll")
public class GetAll extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try (StudentService studentService = new StudentService()) {
            final List<Student> all = studentService.getAll();

            request.setAttribute("all", all);
            request.getRequestDispatcher("/jsp/studentManagementSystem.jsp").forward(request, response);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
